package com.goldcn.sys.model.util;

import com.goldcn.common.BaseCode;

import java.util.HashMap;
import java.util.Map;

public class Result {

	public static final String SUCCESS_CODE = BaseCode.SUCCESS_CODE;
	public static final String ERROR_CODE = BaseCode.ERROR_CODE;
	public static final String CODE = "code";
	public static final String MESSAGE = "message";
	public static final String DATA = "data";


	private Map<String, Object> datas = new HashMap<String, Object>();
	
	public Result(){}

	public Result(Object data){
		put(DATA, data);
	}

	public Result put(String key, Object value)
	{
		datas.put(key, value);
		return this;
	}

	public String toJson() 
	{
		return JsonUtil.toJson(datas);
	}
	
	
	public String returnSuccess(String message)
	{
		put(CODE, SUCCESS_CODE).put(MESSAGE, message);
		return toJson();
	}
	
	public String returnSuccess()
	{
		put(CODE, SUCCESS_CODE);
		return toJson();
	}
	
	public String returnError(String message)
	{
		put(CODE, ERROR_CODE).put(MESSAGE, message);
		return toJson();
	}

	public String returnNoPermission(){
		put(CODE, BaseCode.ERROR_CODE100).put(MESSAGE, "该用户暂无操作权限");
		return toJson();
	}

}
